import request from '@/utils/request.js';

export function getGoodsListAPI(params) {
    return request({
        url: '/goods/list',  // 后端接口的路径
        method: 'get',       // 请求方式为 GET
        params,              // 传递查询参数
    });

}
//     获取分类列表
export function getCategoryListAPI(type) {
    return request({
        url: '/goods/category',  // 后端接口的路径
        method: 'get',       // 请求方式为 GET
        params: { type },
    });

}
export const getProductDetailAPI = (id) => {
    return request({
        url: `/goods/${id}`,
        method: 'get',
    });
};

export const addCartAPI = (cartData) => {
    return request({
        url: '/goods/addCart',
        method: 'post',
        data: cartData,
    });
};

export const getCartAPI = (userId) => {
    return request('/goods/getCart/'+userId);
};

//删除购物车商品
export const deleteCartAPI = (cartId) => {
    return request({
        url: '/goods/deleteCart',
        method: 'delete',
        params: {cartId},
        });
};

//修改购物车商品数量
export const updateCartAPI = (cartId,nums) => {
    return request({
        url: '/goods/updateCart',
        method: 'put',
        params: {cartId,nums},
    });
};
//查询我的商品，分页
//  const response = await getUserGoodsAPI({ userId, page: 1, pageSize: 10 });
export const getUserGoodsAPI = (params) => {
    return request({
        url: '/goods/user',
        method: 'get',
        params,
    });
};

//添加商品
export const addGoodsAPI = (data) => {
    return request({
        url: '/goods/addGoods',
        method: 'post',
        data
    })
}




//上传商品主图
    export const uploadMainImgAPI = (formData) => {
    return request({
        url: '/goods/uploadGoodsImg',
        method: 'post',
        data: formData
    })
}
//删除图片
export const deleteImgAPI = (imgUrl) => {
    return request({
        url: '/goods/deleteImg',
        method: 'delete',
        params: {imgUrl}
    })
}
//删除商品
export const deleteGoodsAPI = (goodsId) => {
    return request({
        url: '/goods/deleteGoods',
        method: 'delete',
        params: {goodsId}
    })
}
//修改商品状态
export const updateGoodsStatusAPI = (goodsId,status) => {
    return request({
        url: '/goods/updateGoodsStatus',
        method: 'put',
        params: {goodsId,status}
    })
}